#include <iostream>

using namespace std;

const int N = 1e4 + 10;

int q[N], h, t;

int main()
{
    int n; cin >> n;
    while(n--)
    {
        int op, x;
        cin >> op;
        if(op == 1) // 进队
        {
            cin >> x;
            q[t++] = x;
        }
        else if(op == 2) // 出队
        {
            if(h == t) cout << "ERR_CANNOT_POP" << endl;
            else h++;
        }
        else if(op == 3) // 队头元素
        {
            if(h == t) cout << "ERR_CANNOT_QUERY" << endl;
            else cout << q[h] << endl;
        }
        else // 元素个数
        {
            cout << t - h << endl;
        }
    }

    return 0;
}